const MyEmitter = require ( 'events' ).EventEmitter;

const myEmitter = new MyEmitter ();
// Only do this once so we don't loop forever
myEmitter.once ( 'newListener', ( event, listener ) => {
    if ( event === 'event' ) {
        // Insert a new listener in front
        myEmitter.on ( 'event', () => {
            console.log ( 'B' );
        } );
    }
} );
myEmitter.on ( 'event', () => {
    console.log ( 'A' );
} );

myEmitter.removeListener ( 'event', () => {
    console.log ( 'B' );
} );
myEmitter.emit ( 'event' );
// Prints:
//   B
//   A